// pages/setting/setting.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    phone: null,
    name: ''
  },
  onShow: function() {
    this.setData({
      name: getApp().globalData.contactText,
      phone: getApp().globalData.phoneText,
    })
  },
  //改变姓名
  nameInput(e) {
    this.setData({
      name: e.detail.value
    })
  },
  //改变电话号码
  changePhone() {
    wx.navigateTo({
      url: '/pages/certification/certification?status=' + true,
    })
  },

  //确认更改信息
  confirmSetting() {
    wx.request({
      url: 'https://api.mokyun.com/pesticide/modify/name',
      method: 'POST',
      header: {
        'Accept': 'application/json',
        'Authorization': 'Bearer ' + wx.getStorageSync('token'),
        'content-type': 'application/json',
        'APPID': 32
      },
      data: {
        name: this.data.name
      },
      success: (res) => {
        console.log(res)
        if (res.data == 'success') {
          wx.showToast({
            title: '修改成功',
            success: (res) => {
              setTimeout(() => {
                wx.reLaunch({
                  url: '/pages/index/index'
                })
              }, 1500)
            }
          })
        }
      }
    })
  }
})